<template>
  <div class="ui-header">
    <div class="ui-top">
      <div class="name-box ui-flex align-center">
        <div class="ui-center ui-flex align-center justify-between">
          <div class="flex-1">
            <div class="name" @click="Jump('/')"></div>
          </div>
          <div class="search-box">
            <div class="search ui-flex justify-center">
              <input type="text" placeholder="请输入关键词" />
              <div class="btn ui-flex align-center">搜索</div>
            </div>
          </div>
          <a href="#" class="btn ui-flex align-center">沉浸式体验</a>
        </div>
      </div>
    </div>
    <img :class="['bg', { hide: isHide || !props.showBanner }]" src="../assets/search-bg.png" />
    <div class="menu-box">
      <div class="ui-center ui-flex align-center">
        <div class="item" @click="Jump('/')">
          <span>首页</span>
        </div>
        <div class="item">
          <span>知识空间</span>
          <div class="second">
            <a class="second-item" href="./listSpace?active=0">四个共同</a>
            <a class="second-item" href="./listSpace?active=1">民族文化走廊专题</a>
          </div>
        </div>
        <div class="item">
          <span>课程案例</span>
          <div class="second">
            <div class="second-item">语文</div>
            <div class="second-item">历史</div>
            <div class="second-item">道德与法治</div>
          </div>
        </div>
        <div class="item" @click="Jump('/listSchoolAndNews?active=0')">
          <span>扎根学校</span>
        </div>
        <div class="item">
          <a href="http://epc.swu.edu.cn/sys/gztd.htm">教育实验平台</a>
        </div>
        <div class="item">
          <span>数据库</span>
        </div>
        <div v-if="props.showBanner" :class="['btn ui-flex align-center', { push: !isHide }, { pull: isHide }]" @click="Toggle">
          {{ isHide ? '展开' : '收起' }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
const { router } = inject('global');

let props = defineProps({
  showBanner: {
    type: Boolean,
    default: () => true
  }
});

let isHide = ref(false);
const Toggle = () => {
  isHide.value = !isHide.value;
};

const Jump = url => {
  router.push(url);
};
</script>

<style lang="scss" scoped>
.ui-top {
  .name-box {
    height: 64px;
    background: #752619;
    font-size: 18px;
    box-sizing: border-box;
    color: #ffffff;
    border-bottom: 1px solid #994133;
    .name {
      width: 436.4px;
      height: 46px;
      @include bgImg('../assets/top-logo.png');
    }
    .btn {
      color: inherit;
      &::before {
        content: '';
        display: block;
        width: 24px;
        height: 24px;
        margin-right: 10px;
        @include bgImg('../assets/immersive.png');
      }
    }
  }
  .search-box {
    margin-right: 20px;
    .search {
      border: 1px solid #9c2c29;
      border-radius: 4px;
      height: 36px;
      width: 213px;
      overflow: hidden;
      padding: 4px 0;
      input {
        flex: 1;
        min-width: 0;
        outline: none;
        padding: 4px 10px;
        box-sizing: border-box;
        border: none;
        font-size: 14px;
        line-height: 20px;
        border-right: 1px solid #9c2c29;
        background-color: transparent;
        color: #ffcec5;
        &::placeholder {
          color: #ffcec5;
        }
      }
      .btn {
        color: #ede8e2;
        padding: 5px 10px;
        flex-shrink: 0;
        font-size: 14px;
        cursor: pointer;
        &::before {
          content: '';
          display: block;
          width: 18px;
          height: 18px;
          margin-right: 10px;
          @include bgImg('../assets/search.png');
        }
      }
    }
  }
}
.bg {
  display: block;
  width: 100%;
  height: 478px;
  object-fit: cover;
  transition: height 1s ease-in-out;
  &.hide {
    height: 0;
  }
}
.menu-box {
  background: #9c2c29;
  height: 54px;
  .ui-center {
    position: relative;
  }
  .item {
    font-size: 18px;
    color: #ffffff;
    padding: 14px 30px;
    line-height: 26px;
    position: relative;
    cursor: pointer;
    a {
      color: inherit;
    }
    &:hover,
    &.on {
      font-weight: bold;
      .second {
        display: block;
      }
    }
    .second {
      display: none;
      position: absolute;
      left: 50%;
      top: 100%;
      transform: translateX(-50%);
      background: rgba(156, 44, 41, 0.8);
      .second-item {
        display: block;
        text-decoration: none;
        font-size: 18px;
        color: #ede8e2;
        padding: 17px 34px;
        line-height: 26px;
        white-space: nowrap;
        text-align: center;
        cursor: pointer;
        &:hover {
          background: #9c2c29;
        }
      }
    }
  }
  .btn {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: #e5afad;
    cursor: pointer;
    &::before {
      content: '';
      display: block;
      width: 36px;
      height: 36px;
      margin-right: 10px;
    }
    &.pull {
      &::before {
        @include bgImg('../assets/pull.png');
      }
    }
    &.push {
      &::before {
        @include bgImg('../assets/push.png');
      }
    }
  }
}
</style>
